<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>08.vue中的动画封装</title>
    <link rel="stylesheet" href="animate.css">
</head>
<body>
    <div id="app">
        <fade v-if="show">
            <div>hello world</div>
        </fade>
        <fade v-if="show">
            <h3>hello world</h3>
        </fade>
        
        <button @click="handleClick">Add</button>
    </div>
</body>
<script src="vue.js"></script>
<script>
    Vue.component('fade', {
        props: ['show'],
        template: `
            <transition name="fade" 
            @before-enter="handleBeforeEnter"
            @enter="handleEnter"
            >
                <slot v-show="show"></slot>
            </transition>
        `,
        methods: {
            handleBeforeEnter: function(el) {
                el.style.color = 'red';
            },
            handleEnter: function(el, done) {
                setTimeout(() => {
                    el.style.color = 'green';
                    done();
                },2000)
            }
        }
    });

    var app = new Vue({
        el: '#app',
        data: {
            show: true
        },
        methods: {
            handleClick: function() {
                this.show = !this.show;
            }
        }
    })
</script>
</html>